home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Codigo / hh / rsource.exe / Hexen Source / I_IBM_A.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-11  |  2.0 KB  |  136 lines

  1.     .386
  2.     .MODEL  small
  3.  
  4. .DATA
  5.  
  6.  
  7.  
  8. .CODE
  9.  
  10. IF 0
  11. #define PEL_WRITE_ADR   0x3c8
  12. #define PEL_READ_ADR    0x3c7
  13. #define PEL_DATA                0x3c9
  14. ENDIF
  15.  
  16. ;================
  17. ;
  18. ; I_DivException
  19. ;
  20. ;================
  21.  
  22. PROC      I_DivException_
  23. PUBLIC     I_DivException_
  24.     mov    edx,03c9h
  25.     mov    al,63
  26.     out    dx,al
  27.  
  28.     mov    ebx,0ffffffh
  29.     mov    eax,[ebx]
  30.     retf
  31. ENDP
  32.  
  33. ;================
  34. ;
  35. ; I_SetDivException
  36. ;
  37. ;================
  38.  
  39. PROC      I_SetDivException_
  40. PUBLIC     I_SetDivException_
  41.     pusha
  42.  
  43.     mov    eax,0212h
  44.     mov    ebx,0
  45.     mov    ecx,cs
  46.     mov    edx,OFFSET I_DivException_
  47.     int 31h
  48.     jnc    good
  49.  
  50.     popa
  51.     mov    eax,0
  52.     ret
  53.  
  54. good:
  55.     popa
  56.     mov    eax,1
  57.     ret
  58.  
  59. ENDP
  60.  
  61.  
  62. ;================
  63. ;
  64. ; I_ReadJoystick
  65. ;
  66. ; Read the absolute joystick values
  67. ; returns false if not connected
  68. ;================
  69.  
  70. .data
  71.  
  72. _joystickx    dd    0
  73. _joysticky    dd    0
  74. PUBLIC    _joystickx, _joysticky
  75.  
  76. .code
  77.  
  78. PROC      I_ReadJoystick_
  79. PUBLIC     I_ReadJoystick_
  80.     pushad
  81.     pushf                    ; state of interrupt flag
  82.     cli
  83.  
  84.     mov        dx,0201h
  85.     in        al,dx
  86.     out        dx,al        ; Clear the resistors
  87.  
  88.     mov        ah,1        ; Get masks into registers
  89.     mov        ch,2
  90.  
  91.     xor        esi,esi        ; Clear count registers
  92.     xor        edi,edi
  93.     xor        ebx,ebx        ; Clear high byte of bx for later
  94.  
  95.     mov        ebp,10000    ; joystick is disconnected if value is this big
  96.  
  97. jloop:
  98.     in        al,dx        ; Get bits indicating whether all are finished
  99.  
  100.     dec        ebp            ; Check bounding register
  101.     jz        bad            ; We have a silly value - abort
  102.  
  103.     mov        bl,al        ; Duplicate the bits
  104.     and        bl,ah        ; Mask off useless bits (in [xb])
  105.     add        esi,ebx        ; Possibly increment count register
  106.     mov        cl,bl        ; Save for testing later
  107.  
  108.     mov        bl,al
  109.     and        bl,ch        ; [yb]
  110.     add        edi,ebx
  111.  
  112.     add        cl,bl
  113.     jnz        jloop         ; If both bits were 0, drop out
  114.  
  115. done:
  116.     mov        [_joystickx],esi
  117.     shr        edi,1        ; because 2s were added
  118.     mov        [_joysticky],edi
  119.  
  120.     popf            ; restore interrupt flag
  121.     popad
  122.     mov    eax,1        ; read was ok
  123.     ret
  124.  
  125. bad:
  126.     popf            ; restore interrupt flag
  127.     popad
  128.     xor     eax, eax    ; read was bad
  129.     ret
  130.  
  131. ENDP
  132.  
  133.  
  134. END
  135.  
  136.